﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/FullSite.Master" Inherits="System.Web.Mvc.ViewPage<ToppingControl.Models.TopCordPlanModel.TopCordPlan_DS>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
   Header_des_com
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

   <div class="float-left">
      <h2>
         Topping Head Computer</h2>
   </div>
   <div class="float-right">
      <div class="float-left">
         <h3>
            Topping NO.
            <%: Html.DisplayFor(model => model._Topno) %>
         </h3>
      </div>
      <div class="float-left" style="margin-left: 25px;">
         <h3>
            Shift : <%: ViewBag.shift %></h3>
      </div>
      <div class="float-left" style="margin-left: 25px;">
         <h3>
            Name :
            <% if (Request.IsAuthenticated)
               { %>
            <%:  User.Identity.Name %></h3>
      </div>
      <% } %>
   </div>
   <style type="text/css">
      .fontTB
      {
         font-size: 18pt !important;
      }
      #txtComp
      {
         font-size: 1em;
         height: 2em;
         line-height: 2.5em;
      }
           .btn
      {
         font-size: 24px !important;
       
      }
      /* Bigger text */</style>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
    <div class="float-left" style="margin: 10px;">
               <input id="back" type="button" value="BACK" class="btn" style="height: 75px; width: 350px;" />
            </div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="MainContent2" runat="server">
    <br />
   <% 
      string Itemno = "";
      if (WinNemoLib.StrUtil.IsNotEmpty(Model._Itemno))
      {
         Itemno = Model._Plandt + '-' + Model._Itemno;

      } %>
   <table width="75%" class="fontTB" style="height:82%">
      <tr class="rowa">
         <td class="head cell " style="padding: 10px 0px; color:White; background-color:#20B2AA" colspan="2">
             Compound Change</td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px; width: 35%;">
            SEQ
         </td>
         <td class="cell" id="seqDT">
            <%= Itemno %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Topped Cord
         </td>
         <td class="cell">
            <%= Model._Topcrdcd%>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Manufacturer
         </td>
         <td class="cell">
            <%= Model._Manufc %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Length (M.)
         </td>
         <td class="cell">
            <%= Model._Length%>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord
         </td>
         <td class="cell" id="code">
            <%= Model._Tcrdcd %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord Lot
         </td>
         <td class="cell" id="lot">
            <%=Model._Tcrdlot %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord Expire
         </td>
         <td class="cell" id="exp">
            <%=Model._Tcrdexp %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord Tag Length (M.)
         </td>
         <td class="cell">
            <%=Model._Tcrdtagl %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord Tag Width (cm.)
         </td>
         <td class="cell">
            <%=Model._Tcrdtagw %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Tire Cord Width (cm.)
         </td>
         <td class="cell">
            <%=Model._Tcrdw %>
         </td>
      </tr>
      <tr class="rowb">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Compound
         </td>
         <td class="cell" id="mComp">
            <%=Model._Compcd %>
         </td>
      </tr>
      <tr class="rowa">
         <td class="head cell text-right" style="padding: 10px 0px;">
            Compound Confirm
         </td>
         <td class="cell" id="comp">
            <input type="password" id="txtComp" style="width: 55%" />
         </td>
      </tr>
     
   </table>
   <input type="hidden" id="blnExp" value="" />
   <%--/**** BODY *****/--%>
   <div id="dialog-a" title="Compound is expired">
      <div class="cap cell">
         Compound</div>
      <div class="desc cell" id="dcode">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Compound Lot</div>
      <div class="desc cell" id="dLot">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Compound Pallet</div>
      <div class="desc cell" id="dPalt">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Compound Expired</div>
      <div class="desc cell" id="dexp">
      </div>
      <div style="clear: left">
      </div>
      <div class="cap cell">
         Compound (Kg.)</div>
      <div class="desc cell" id="dWeg">
      </div>
   </div>
   <%--//************ dialog *******************//--%>
   <div id="dialog-b" title="Use Compound">
      <table style="width: 98%;" class="fontTB">
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px; width: 30%">
               Emp code
            </td>
            <td class="cell">
               <input type="text" id="txtempnm" style="width: 75%" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Password
            </td>
            <td class="cell">
               <input type="password" id="txtpass" style="width: 75%" />
            </td>
         </tr>
         <tr class="rowa">
            <td class="head cell text-right" style="padding: 10px 0px;">
               Short Text
            </td>
            <td class="cell">
               <input type="text" id="txtshort" maxlength="30" style="width: 75%" />
            </td>
         </tr>
      </table>
   </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ScriptsSection" runat="server">
    <% if (false)
      { %>
   <script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
   <% } %>
   <script type="text/javascript">
       $(function () {
           /*************** dialog *************/

           $("#dialog-a").dialog({
               width: 500,
               height: 400,
               autoOpen: false,
               show: "blind",
               resizable: false, //สั่งให้ไม่สามารถย่อขยายได้
               modal: true,  //สั่งให้มีฉากเบลอๆด้านหลัง dialog
               open: function (event, ui) {
                   $(this).parent().children(".ui-widget-header").css("background", "#B22222");
                   $(this).parent().children(".ui-dialog-titlebar").css("color", "white");
                   $("#txtempnm").val("");
                   $("#txtpass").val("");
                   $("#txtshort").val("");
               },
               buttons: {
                   "Back": function () {
                       $(this).dialog("close");

                   },
                   "Use Compound": function () {
                       $(this).dialog("close");
                       $("#dialog-b").dialog("open");
                   }
               }
           });

           $("#dialog-b").dialog({
               width: 650,
               height: 400,
               autoOpen: false,
               show: "blind",
               buttons: {
                   "Back": function () {
                       $(this).dialog("close");
                   },
                   "OK": function () {
                       if ($("#txtempnm").val() == "") {
                           alert("ระบุข้อมูลไม่ครบ");
                           $("#TCLen").focus();
                           return;
                       }
                       if ($("#txtpass").val() == "") {
                           alert("ระบุข้อมูลไม่ครบ");
                           $("#TCLen").focus();
                           return;
                       }
                       if ($("#txtshort").val() == "") {
                           alert("ระบุข้อมูลไม่ครบ");
                           $("#TCLen").focus();
                           return;
                       }

                       $.post('<%=Url.Action("Get_Author","HeaderLine") %>' + '?users=' + $("#txtempnm").val() + '&pass=' + $("#txtpass").val()
                  , function (data) {
                      if (data.success == 0) {
                          alert(data.message);
                      }
                      else {
                          $("#dialog-b").dialog("close");
                          $("#blnExp").val("");
                          SaveData();
                      }
                  }); // POST
                   } //ok
               }//button
           });

           ////  BACK ////////
           $("#back").click(function () {
               var localB = getUrlVars()["back"];               
               var getUsersUrl = '<%= Url.Action("Header_Run","HeaderLine") %>' + '?seq=' + $.trim($("#seqDT").text())
               getUsersUrl = getUsersUrl + '&shift=' + '<%: Model._Shift %>';
                if(typeof(localB)  != "undefined"){
                   getUsersUrl = localB + '?seq=' + $.trim($("#seqDT").text());
               }
               window.location = getUsersUrl;
           });

           /******* TEXT BARCODE **********/

           $('#txtComp').focus().blur(function () {
               if ($(this).val() == "") {
                   return;
               } else {
                   if (!GET_Barcode($(this).val())) {
                       alert(" ข้อมูลไม่ถูกต้อง ");
                       $(this).focus().val("");
                   }
               }
           });


           function GET_Barcode(barcode) {
               var myArray = barcode.split('+');

               if (myArray.length != 4) {
                   return false;
               }
               var cpd = $.trim($("#mComp").text());

               if (cpd != $.trim(myArray[0])) {
                   return false;
               }

               $("#dcode").text(myArray[0]);
               var LP = myArray[1].split('R');
               $("#dLot").text(LP[0]);
               $("#dPalt").text('R' + LP[1]);
               $("#dWeg").text(myArray[2]);

//               var d = myArray[3].substring(0, 4);
//               d = d + "-" + myArray[3].substring(4).substring(0, 2);
//               d = d + "-" + myArray[3].substring(6);
               $.post('<%=Url.Action("ConvertDate","HeaderLine") %>' + '?sdate=' + myArray[3], function (data) {
                   $("#dexp").text(data.message);

                   if ($.trim(data.bln) != "true") {
                       $("#dialog-a").dialog("open");
                   }
                   else {
                       $("#txtempnm").val("");
                       $("#txtpass").val("");
                       $("#txtshort").val("");
                       SaveData();
                   }
               });
               return true;
           }

           function SaveData() {
               var reason = ""
               if ($("#txtshort").val() != "") {
                   reason = "Compound is expired";
               }

               var dataForSubmit = new Array();
               dataForSubmit.push({
                   _Topno: '<%: Model._Topno %>',
                   _Plandt: '<%: Model._Plandt %>',
                   _Itemno: '<%: Model._Itemno %>',
                   _Cauthemp: $("#txtempnm").val(),
                   _Cshtxt: $("#txtshort").val(),
                   _Compcd: $("#dcode").text(),
                   _Complot: $("#dLot").text(),
                   _Creatxt: reason,
                   _Cshtxt: $("#txtshort").val(),
                   _Comppllt: $("#dPalt").text(),
                   _Compexp: $("#dexp").text(),
                   _Compw: $("#dWeg").text()

               });

               var getUsersUrl = '<%= Url.Action("Save_Change_CPD","CPD_USE") %>';
               callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
           }
           /********* AJAX ********/

           function callScriptMethod(url, jsonObject, action, callback, async) {

               callback = callback || function () { };
               async = (async == null || async);

               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: url,
                   data: JSON.stringify(jsonObject),
                   dataType: "json",
                   async: async,
                   success: function (data) {

                       if (data.success != "0") {
                           var getUsersUrl = '<%= Url.Action("Header_Run","HeaderLine") %>' + '?seq=' + $.trim($("#seqDT").text())
                           getUsersUrl = getUsersUrl + '&shift=' + '<%: Model._Shift %>';
                           window.location = getUsersUrl;
                       } else alert(data.message);
                   },
                   error: function (xhr, status, error) {
                       var err = xhr.responseText;
                       alert(err.Message);
                   }
               });
           }
       });


   </script>
</asp:Content>
